package com.cogwheel.framework.util.input;

import javax.media.opengl.awt.GLCanvas;

import com.cogwheel.framework.util.CPoint;

public class CMouse {
	private CMouseListener mListener = new CMouseListener();
	private long lTime = 0;
	
	public void CWGRegisterListener(GLCanvas canvas){
		canvas.addMouseMotionListener(mListener);
		canvas.addMouseListener(mListener);
		
		//resetThread.start();
	}
	public void CWGUnregisterListener(GLCanvas canvas){ canvas.removeMouseMotionListener(mListener); canvas.removeMouseListener(mListener); resetThread = null; }
	public CPoint CWGGetMouseCoords(){ return mListener.Position; }
	public CMouseState CWGGetMouseState(){ return mListener.MouseState; }
	public void CWGSetMouseState(CMouseState state){ mListener.MouseState = state; }
	public Thread resetThread = new Thread(new Runnable(){
		@Override
		public void run() {
			while(true){
				if (System.currentTimeMillis() - lTime >= 1000/20){
					if (mListener.MouseState == CMouseState.LEFT_CLICK || mListener.MouseState == CMouseState.RIGHT_CLICK ||
						mListener.MouseState == CMouseState.LEFT_UP || mListener.MouseState == CMouseState.RIGHT_UP){
						mListener.MouseState = CMouseState.NOTHING;
					}
					lTime = System.currentTimeMillis();
				}
			}
		}
	});
}
